/**
 * Created by zes on 2018-01-19 13:47:54
 */

export default {
  // 登录权限
  login: function(v) {
    let setPermission = JSON.parse(window.sessionStorage.getItem("setper")),
      authResult = false;
    if (!setPermission) return authResult;
    switch (v) {
      case "login:backstage":
        authResult = setPermission.indexOf("login:backstage") != -1;
        break;
      case "login:frontEnd":
        authResult = setPermission.indexOf("login:frontEnd") != -1;
        break;
      default:
        authResult = false;
    }
    return authResult;
  },
  // 用户/帐号管理
  usermanager: function(v) {
    let setPermission = JSON.parse(window.sessionStorage.getItem("setper")),
      authResult = false;
    if (!setPermission) return authResult;
    switch (v) {
      case "usermanager:add":
        authResult = setPermission.indexOf("usermanager:add") != -1;
        break;
      case "usermanager:delete":
        authResult = setPermission.indexOf("usermanager:delete") != -1;
        break;
      case "usermanager:edit":
        authResult = setPermission.indexOf("usermanager:edit") != -1;
        break;
      case "usermanager:search":
        authResult = setPermission.indexOf("usermanager:search") != -1;
        break;
      default:
        authResult = false;
    }
    return authResult;
  },  
  // 设备管理
  equipment: function(v) {
    let setPermission = JSON.parse(window.sessionStorage.getItem("setper")),
      authResult = false;
    if (!setPermission) return authResult;
    switch (v) {
      case "equipment:add":
        authResult = setPermission.indexOf("equipment:add") != -1;
        break;
      case "equipment:delete":
        authResult = setPermission.indexOf("equipment:delete") != -1;
        break;
      case "equipment:edit":
        authResult = setPermission.indexOf("equipment:edit") != -1;
        break;
      case "equipment:search":
        authResult = setPermission.indexOf("equipment:search") != -1;
        break;
      default:
        authResult = false;
    }
    return authResult;
  },
  // ap管理
  apmanager: function(v) {
    let setPermission = JSON.parse(window.sessionStorage.getItem("setper")),
      authResult = false;
    if (!setPermission) return authResult;
    switch (v) {
      case "apmanager:add":
        authResult = setPermission.indexOf("apmanager:add") != -1;
        break;
      case "apmanager:delete":
        authResult = setPermission.indexOf("apmanager:delete") != -1;
        break;
      case "apmanager:edit":
        authResult = setPermission.indexOf("apmanager:edit") != -1;
        break;
      case "apmanager:search":
        authResult = setPermission.indexOf("apmanager:search") != -1;
        break;
      default:
        authResult = false;
    }
    return authResult;
  },
  // web页面设置管理
  websetting: function(v) {
    let setPermission = JSON.parse(window.sessionStorage.getItem("setper")),
      authResult = false;
    if (!setPermission) return authResult;
    switch (v) {
      case "websetting:add":
        authResult = setPermission.indexOf("websetting:add") != -1;
        break;
      case "websetting:delete":
        authResult = setPermission.indexOf("websetting:delete") != -1;
        break;
      case "websetting:edit":
        authResult = setPermission.indexOf("websetting:edit") != -1;
        break;
      case "websetting:search":
        authResult = setPermission.indexOf("websetting:search") != -1;
        break;
      default:
        authResult = false;
    }
    return authResult;
  }
};
